package com.ccjk.beusoft.hot;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.RequiresApi;
import android.support.v7.view.menu.MenuWrapperFactory;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import dalvik.system.DexClassLoader;

/**
 * Created by CCJK on 2017/12/1.
 */

public class Util {
    public static void start(DexClassLoader dexClassLoader, String apkPath, Class<?> targetClass, String targetClassName, Activity proxy){
        try {
            Constructor constructor= targetClass.getConstructor(new Class[]{});
            Object taregetActivity= constructor.newInstance(new Object[]{});
            //
            Method setProxy=targetClass.getMethod("setProxy",new Class[]{Activity.class});
            setProxy.setAccessible(true);
            setProxy.invoke(taregetActivity,new Object[]{proxy});
            //
            Method onCreate=targetClass.getMethod("onCreate",new Class[]{Bundle.class});
            onCreate.setAccessible(true);
            Bundle bundle=new Bundle();
            bundle.putInt(ProxyActivity.Companion.getFROM(),ProxyActivity.Companion.getEXTERNAL());
            onCreate.invoke(taregetActivity,new Object[]{bundle,null});
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    }




}
